package com.atguigu.b_udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class Sender {//发送端

    public static void main(String[] args) throws IOException {
        //创建UDP发送端的对象
        DatagramSocket ds = new DatagramSocket();

        //创建数据包对象,并把数据包进行封装 -> DatagramPacket
        //DatagramPacket(byte[] buf, int offset, int length, InetAddress address, int port)
        String line = "上课好好听讲";
        DatagramPacket p = new DatagramPacket(line.getBytes(),0,line.getBytes().length
                , InetAddress.getByName("192.168.16.61"),
                10086);

        //发送数据
        ds.send(p);

        //关闭资源 -> 一般不管 通讯不是一次性
        //ds.close();
    }
}
